//
//  MLABaseViewController.m
//  MagicLampApp
//
//  Created by Zheng on 2018/12/17.
//  Copyright © 2018 zheng.magic.lamp.app. All rights reserved.
//

#import "MLABaseVC.h"

@interface MLABaseVC ()

@end

@implementation MLABaseVC

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    if (self.navigationController.viewControllers.count > 1) {
        UIButton *backButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [backButton setImage:[UIImage imageNamed:@"back_icon"] forState:UIControlStateNormal];
        backButton.frame = CGRectMake(0,0,40,40);
        backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -30, 0, 0);
        [backButton addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
        self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    }
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    if (self.navigationController.viewControllers.count > 1) {
        self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    }else{
        self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
}

- (void)configRightItemWithTitle:(NSString *)title {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setTitle:title forState:UIControlStateNormal];
    btn.titleLabel.font = CX_GetNormalFont(15);
    [btn setTitleColor:CX_GetColorTitle() forState:UIControlStateNormal];
    btn.frame = CGRectMake(0,0,40,40);
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn addTarget:self action:@selector(rightItemAction) forControlEvents:UIControlEventTouchUpInside];
}


- (void)configLeftItemWithImage:(NSString *)image {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    btn.frame = CGRectMake(0,0,40,40);
    btn.contentEdgeInsets = UIEdgeInsetsMake(0, -25, 0, 0);
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn addTarget:self action:@selector(leftItemAction) forControlEvents:UIControlEventTouchUpInside];
}

- (void)configRightItemWithImage:(NSString *)image {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
    btn.frame = CGRectMake(0,0,40,40);
    btn.contentEdgeInsets = UIEdgeInsetsMake(0, 25, 0, 0);
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    [btn addTarget:self action:@selector(rightItemAction) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark - Actions
- (void)backAction {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)leftItemAction {}
- (void)rightItemAction {}

#pragma mark - CommonMethod
- (UIButton *)getCommitButtonWithTitle:(NSString *)title {
    UIButton *commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [commitBtn setTitle:title forState:UIControlStateNormal];
    [commitBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    commitBtn.titleLabel.font = CX_GetNormalFont(14);
    commitBtn.backgroundColor = CX_GetColorBlue();
    commitBtn.layer.cornerRadius = 5;
    return commitBtn;
}




@end
